﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ArtemisTest
{

    public class MovementSystem : CSystem
    {
        public void SetPosActions(double dt)
        {
            Dictionary<long, Component> setPosArray = EntitySystem.Components.GetAllComponentsOfType(ComponentType.set_pos);
            Dictionary<long, Component> PosArray = EntitySystem.Components.GetAllComponentsOfType(ComponentType.position);

            List<long> toRemove = new List<long>();

            foreach (KeyValuePair<long, Component> entry in setPosArray)
            {
                Position pos = (Position)PosArray[entry.Key];
                SetPos spos = (SetPos)entry.Value;
                if (Exists(pos))
                {
                    pos.X = spos.X;
                    pos.Y = spos.Y;
                    toRemove.Add(pos.UID);

                }
            }
            foreach (long uid in toRemove)
            {
                EntitySystem.Components.RemoveComponent(ComponentType.set_pos, uid);
            }
        }

        public override void Update(double dt)
        {
            SetPosActions(dt);
        }

        public override void Init()
        {

        }

        public MovementSystem(EntitySystem es, ScriptSystem ss) : base(es, ss) { }

        public override void PreUpdate(double dt)
        {
        }

        public override void PostUpdate(double dt)
        {
        }
    }
}
